﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;

using System.ServiceModel.Web;
using System.Text;
using System.IO;

namespace UploadWcfService
{


    // 注意: 如果更改此处的接口名称 "IUpLoadService"，也必须更新 Web.config 中对 "IUpLoadService" 的引用。
    [ServiceContract]
    public interface IUpLoadService
    {
        [OperationContract(Action = "UploadFile", IsOneWay = true)]
        void UploadFile(FileUploadMessage request);
        
        [OperationContract(Action = "UploadProduct", IsOneWay = true)]
        void UploadProduct(string json);
        
        [OperationContract(Action = "GetProduct", IsOneWay = false)]
        FileUploadMessage GetProduct(DownloadRequest request);

        [OperationContract(Action = "GetFiles", IsOneWay = false)]
        IList<string> GetFiles();

        [OperationContract(Action = "GetSNFiles", IsOneWay = false)]
        IList<string> GetSNFiles(string SN,bool isSourceFile);

        [OperationContract(Action = "IsExistsProduct", IsOneWay = false)]
        bool IsExistsProduct(string SN);
        

        [OperationContract(Action = "DeleteProuct", IsOneWay = false)]
        void DeleteProuct(string SN);

        [OperationContract(Action = "DeleteProuctImages", IsOneWay = false)]
        void DeleteProuctImages(string Images);

        [OperationContract(Action = "SetFlag", IsOneWay = false)]
        void SetFlag(string SN, string Flag);

        [OperationContract(Action = "GetUploadFileInfo", IsOneWay = false)]
        int GetUploadFileInfo(string filePath);

        [OperationContract(Action = "GetProductImages", IsOneWay = false)]
        IList<string> GetProductImages(string productid);

        [OperationContract(Action = "GetProductsBySN", IsOneWay = false)]
        IList<iSun.Entity.ProductPhotoEnitty> GetProductsBySN(string SN);


    }

    [MessageContract]
    public class DownloadRequest
    {
        [MessageBodyMember]
        public string FileName;
    }

  


    [MessageContract]
    public class FileUploadMessage
    {

        [MessageHeader(MustUnderstand = true)]
        public string SavePath;

        [MessageHeader(MustUnderstand = true)]
        public string JsonData;

        [MessageHeader(MustUnderstand = true)]
        public string FileName;

        [MessageBodyMember(Order = 1)]
        public Stream FileData;

        public void Dispose()
        {
            if (FileData != null)
            {
                FileData.Close();
                FileData = null;
            }
        }  
    }

    [DataContract]
    public class FileData
    {
       [DataMember(Order = 1)]
        public Stream Data;
    }
}
